package com.beaven.imclient.widget;

import android.app.AlertDialog;
import android.app.Dialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.v4.app.DialogFragment;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.EditText;
import com.beaven.imclient.R;
import com.beaven.imclient.activity.CategoryActivity;

/**
 * author: Beaven
 * time: 2017/5/31 10:52
 */

public class CategoryDialogFragment extends DialogFragment {

  public static CategoryDialogFragment newInstance() {
    return new CategoryDialogFragment();
  }

  @NonNull @Override public Dialog onCreateDialog(Bundle savedInstanceState) {
    View view = LayoutInflater.from(getContext()).inflate(R.layout.item_category_edit, null);
    final EditText edit_cate = (EditText) view.findViewById(R.id.edit_cate);
    return new AlertDialog.Builder(getActivity()).setView(view)
        .setPositiveButton("确定", new DialogInterface.OnClickListener() {
          @Override public void onClick(DialogInterface dialog, int which) {
            ((CategoryActivity) getActivity()).create(edit_cate.getText().toString().trim());
          }
        })
        .setNegativeButton("取消", new DialogInterface.OnClickListener() {
          @Override public void onClick(DialogInterface dialog, int which) {
            dismiss();
          }
        })
        .create();
  }
}
